package com.xci.sys.api;

import com.xci.core.base.ApiController;
import com.xci.core.base.RestMessage;
import com.xci.core.internal.Const;
import com.xci.core.helper.ExcelHelper;
import com.xci.core.annotation.Authorize;
import com.xci.core.domain.LockUserModel;
import com.xci.sys.service.LockUserService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 锁定用户接口
 * @author 吕艳阳
 */
@ApiSort(9)
@Api(tags = "锁定用户接口")
@Authorize
@RestController
@RequestMapping(value = "/api/sys/lockUser", produces = Const.P_JSON)
public class LockUserApiController extends ApiController {
    /**
     * 锁定用户服务
     */
    @Resource
    private LockUserService lockUserService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "添加锁定用户")
    @ApiImplicitParam(name = "account", value = "账号", required = true)
    @PostMapping("/add")
    public RestMessage add(String account) {
        lockUserService.add(account);
        return RestMessage.success();
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "移除锁定用户")
    @ApiImplicitParam(name = "account", value = "账号", required = true)
    @Authorize(code = "sys.lockUser.remove")
    @PostMapping("/remove")
    public RestMessage remove(String account) {
        lockUserService.remove(account);
        return RestMessage.success();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "查询单个锁定用户")
    @ApiImplicitParam(name = "account", value = "账号", required = true)
    @PostMapping("/get")
    public RestMessage<LockUserModel> get(String account) {
        return RestMessage.success(lockUserService.get(account));
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "查询锁定用户列表")
    @PostMapping("/query")
    public RestMessage<List<LockUserModel>> query() {
        return RestMessage.success(lockUserService.query(null));
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "导出锁定用户列表")
    @Authorize(code = "sys.lockUser.export")
    @PostMapping(value = "/export", produces = {Const.P_OCTET, Const.P_JSON})
    public void export() {
        ExcelHelper.exportWeb(lockUserService.query(null), LockUserModel.class, "锁定用户列表");
    }
}